<head>
    <meta charset="UTF-8">
<title>算法提高 去注释</title>
<link rel="stylesheet" href="../css/main.css">
</head>
 <p>﻿</p>
<h2 style="text-align: center; margin: 13pt 0cm" align="center"><span style="font-family: 黑体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">去注释</span></h2>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">【问题】</font></span></p>
<p style="text-indent: 21pt; margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">给你一段</span><span lang="EN-US"><font face="Times New Roman">C++</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码，将其中的注释去除后输出剩余的代码。</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-tab-count: 1"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注释共有两种形式：</span></font></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 39pt; mso-list: l0 level1 lfo1; tab-stops: list 39.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'" lang="EN-US"><span style="mso-list: Ignore"><font face="Times New Roman"><font size="3">1.</font><span style="font: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span></span><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行注视：以</span><span lang="EN-US"><font face="Times New Roman">//</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开头，一直作用到行尾为止。</span></font></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">例子：</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><font size="3"><span lang="EN-US"><font face="Times New Roman">int n;<b style="mso-bidi-font-weight: normal">//n</b></font></span><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示数据规模</span><span lang="EN-US"><o:p></o:p></span></b></font></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int a;</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">去注释后：</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int n;</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int a;</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">注意：保留行尾换行符</font></span></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 39pt; mso-list: l0 level1 lfo1; tab-stops: list 39.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'" lang="EN-US"><span style="mso-list: Ignore"><font face="Times New Roman"><font size="3">2.</font><span style="font: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></span></span><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">段注视：以</span><span lang="EN-US"><font face="Times New Roman">/*</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开头，到</span><span lang="EN-US"><font face="Times New Roman">*//</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">结尾，中间部分都是注释，可以跨行。</span></font></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">例子：</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int main() {</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">/*</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Times New Roman">&nbsp;</font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我是</span></font></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><span style="mso-spacerun: yes"><font size="3" face="Times New Roman">&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">一段</font></span></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注释</span></font></p>
<p style="margin: 0cm 0cm 0pt 39pt" class="MsoNormal"><span lang="EN-US"><font face="Times New Roman"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp; </span>*/<br />
}</font></font></span></p>
<p style="margin: 0cm 0cm 0pt 21pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-tab-count: 1"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">去注释后：</span></font></p>
<p style="margin: 0cm 0cm 0pt 21pt" class="MsoNormal"><span lang="EN-US"><font face="Times New Roman"><font size="3"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>int main() {</font></font></span></p>
<p style="margin: 0cm 0cm 0pt 21pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt 21pt" class="MsoNormal"><span lang="EN-US"><font face="Times New Roman"><font size="3"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</font></font></span></p>
<p style="margin: 0cm 0cm 0pt 21pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-tab-count: 1"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意：由于在线评测系统（</span><span lang="EN-US"><font face="Times New Roman">Online Judge</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）对网页显示文本作了格式化，一些空行会被删去，导致上面显示的删除后的结果不正确。删除注释后，剩余的代码应该是三行，两行代码之间有一个空行。这是因为：在段注释结尾符的后面有一个换行符，它不在注释内，需要保留。</span></font></p>
<p style="margin: 0cm 0cm 0pt 21pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">【输入】</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-tab-count: 1"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一段</span><span lang="EN-US"><font face="Times New Roman">C++</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序代码</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">【输出】</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-tab-count: 1"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">去掉注释部分后的程序</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">【样例输入】</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int main() {</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">/*</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Times New Roman">&nbsp;</font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我是</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Times New Roman">&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一段</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Times New Roman">&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注释</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">*/</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span lang="EN-US"><font face="Times New Roman">int n;//n</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示数据规模</span></font><span lang="EN-US"><br />
<font size="3" face="Times New Roman">}</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">【样例输出】</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int main() {</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">int n;</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font size="3" face="Times New Roman">}</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font size="3" face="Times New Roman">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意：和之前题目中的解释一样，在</span><span lang="EN-US"><font face="Times New Roman">int n;</font></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之前有一个空行，被在线评测系统删掉，实际程序输出应该有该空行。</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">&nbsp;</p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">【输入方法】</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此题按字符输入，即不断输入下一个字符，直到字符流结束。</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">char c;</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">C函数方法：</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">while ((c = getchar()) != EOF) {</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">处理..</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">}</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">C++流方法：</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">while ((c = cin.get()) != EOF) {</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">处理..</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">}</span></font></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal">&nbsp;</p>